/*
 * network level 
 1io thread
 2msg thread

 network obj.setiothread_function and setmsgthread_function
 network obj can stop and restart
 */

#ifndef _NETWORK_H
#define _NETWORK_H

#include <arpa/inet.h>
#include <netinet/in.h>
#include "netio.h"
#include "appsession.h"

typedef void (*connected_listerner)(AppSession *session, struct sockaddr *addr);
typedef void (*closed_listener)(AppSession *session);
typedef void (*msg_listener)(AppSession *session, void *msg);
typedef void (*error_listener)(AppSession *session, void *err);

struct _network {
	struct sockaddr *addr;
	u_int16_t port;
	u_int32_t rece_buf_size;
	u_int32_t send_buf_size;
	u_int32_t overload;
	u_int32_t listenfd;

	connected_listerner connected;
	closed_listener closed;
	msg_listener received;
	msg_listener sent;
	error_listener error;

	int running;
};
typedef struct _network Network;

extern int start_work(Network *network, NetIO *io);
extern int stop_work(Network *network);

#endif
